#include <vector>
using namespace std;
/*
 * @lc app=leetcode.cn id=75 lang=cpp
 *
 * [75] 颜色分类
 */

// @lc code=start
class Solution {
public:
    // 0 0 1 1 1 2 0
    void sortColors(vector<int>& nums) {
        int lz = 0, lo = 0;
        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] == 0) {
                swap(nums[i], nums[lz]);
                if (lz == lo) lz++, lo++;
                else lz++;
            }
            if (nums[i] == 1) {
                swap(nums[i], nums[lo]);
                lo++;
            }
        }
    }
};
// @lc code=end

